package com.example.floatingpopulation.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import com.example.floatingpopulation.controller.request.BaseRequest;
import com.example.floatingpopulation.entity.JurisdictionalUnit;
import com.example.floatingpopulation.mapper.JurisdictionalUnitMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class JurisdictionalUnitServiceImpl implements com.example.floatingpopulation.service.JurisdictionalUnitService {

    @Autowired
    JurisdictionalUnitMapper jurisdictionalUnitMapper;
    @Override
    public List<JurisdictionalUnit> list() {
        return jurisdictionalUnitMapper.list();
    }

    @Override
    public PageInfo<JurisdictionalUnit> page(BaseRequest baseRequest) {
        PageHelper.startPage(baseRequest.getPageNum(),baseRequest.getPageSize());
        List<JurisdictionalUnit> users = jurisdictionalUnitMapper.listByCondition(baseRequest);
        return new PageInfo<>(users);
    }

    @Override
    public void save(JurisdictionalUnit obj) {
        jurisdictionalUnitMapper.save(obj);
    }

    @Override
    public void update(JurisdictionalUnit obj) {
        obj.setUpdateTime(new Date());
        jurisdictionalUnitMapper.updateById(obj);
    }

    @Override
    public void deleteById(Integer id) {
        jurisdictionalUnitMapper.deleteById(id);
    }
}
